
package com.phevos.web;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.phevos.web.util.RequestUtil;

public class LogoutServlet extends HttpServlet
{
    /**
     * 
     */
    private static final long serialVersionUID = -2755757551848250092L;
    //private static final String CONTENT_TYPE = "text/plain";

    /**
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws ServletException
     * @throws IOException
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        String webAppName = RequestUtil.getParameterWhitDefault(request, "webappName", "unionmon");
        HttpSession session = request.getSession();
        Enumeration enumeration = session.getAttributeNames();
        while (enumeration.hasMoreElements())
        {
            String name = (String)enumeration.nextElement();
            session.removeAttribute(name);
        }
        StringBuffer sb = new StringBuffer();
        if (request.isSecure())
            sb.append("https://");
        else
            sb.append("http://");
        sb.append(request.getHeader("Host"));
        // sb.append(request.getRequestURL());
        sb.append(webAppName);
        response.sendRedirect(sb.toString());
        return;
        // response.setCharacterEncoding("gb2312");
        // PrintWriter out = response.getWriter();
        // String s = request.getRequestURI();
        // out.println(s);
        // s = request.getPathInfo();
        // out.println(s);
        // String host = request.getHeader("Host");
        // out.println(host);
        // out.println("Request URI: " + request.getRequestURI() + " ");
        // out.println("Servlet Path: " + request.getServletPath() + " ");
        // String sss = request.getContextPath();
        // out.close();
    }

    /**
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws ServletException
     * @throws IOException
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        doGet(request, response);
    }
}
